﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Utils.MathUtilitys;
using Utils.Physics2D.Objects;

namespace Utils.Physics2D.Collision
{
    public class CircleCollider : CollisionHandler
    {
        public CircleCollider(PhysicsObject owner)
            : base(owner)
        {

        }

        public override bool CheckCollision(PhysicsObject obj, DISPLACE displacement)
        {
            Vector2 dir = owner.Pos - obj.Pos;
            if(dir.LengthSquared() <= MathUtils.Sqr(owner.Radius + obj.Radius))
            {
                if(displacement != DISPLACE.NONE)
                {
                    PushByDir(obj, displacement, dir * (dir.Length() - (owner.Radius + obj.Radius)));
                }
                return true;
            }
            return false;
        }
    }
}
